package com.bjpowernode.boss.mvc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjpowernode.boss.common.consants.SysConstants;
import com.bjpowernode.boss.convert.PaymentConvert;
import com.bjpowernode.boss.dao.entity.PayProduct;
import com.bjpowernode.boss.dao.result.DicEntity;
import com.bjpowernode.boss.mvc.models.AjaxResult;
import com.bjpowernode.boss.mvc.models.form.product.PayProductForm;
import com.bjpowernode.boss.mvc.models.pages.PageInfo;
import com.bjpowernode.boss.mvc.service.PayProductService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class PayProductController extends BaseController {


    @Resource
    private PayProductService payProductService;
    @Resource
    private PaymentConvert paymentConvert;

    @GetMapping("/payment/product/pageList")
    public AjaxResult pageList(Integer pageNo) {
        pageNo = defPageNo(pageNo);
        IPage<PayProduct> pageResult = payProductService.pageList(pageNo, SysConstants.PAGE_SIZE);
        PageInfo pageInfo = new PageInfo(pageResult.getCurrent(), pageResult.getPages());
        List<PayProduct> payProductsList = pageResult.getRecords();
        Map<String, Object> data = new HashMap<>();
        data.put("page", pageInfo);
        data.put("List", paymentConvert.toListPayProductVo(payProductsList));
        return AjaxResult.ok(data);
    }

    @PostMapping("/payment/product/add")
    public AjaxResult addPayProduct(@RequestBody @Validated PayProductForm productForm) {
        payProductService.addPayProduct(productForm);
        return AjaxResult.ok();
    }

    @GetMapping("/payment/product/dicList")
    public AjaxResult queryProductDicList() {
        List<DicEntity> dicEntityList = payProductService.queryProductDicList();
        return AjaxResult.ok(dicEntityList);
    }
}
